//跳转详情页
function details() {
    $('#list>div').click(function () {
        let id_a = $(this).attr('id')
        location.href = `details.html?id=${id_a}`
    })
    $('#morelist>div').click(function () {
        let id_a = $(this).attr('id')
        location.href = `details.html?id=${id_a}`
    })
}

//搜索
$('.start_a').click(function () {
    let value_1 = $('.start_b').val()
    if (value_1 == '') {
        return
    }
    else {
        location.href = 'search.html?word=' + value_1
        $('.start_b').val('')
    }
})

//栏目跳转
$('.tz_0').click(function () {
    location.href = 'index.html'
})
$('.tz_1').click(function () {
    location.href = 'super.html?h=29'
})
$('.tz_2').click(function () {
    location.href = 'super.html?h=170'
})
$('.tz_3').click(function () {
    location.href = 'super.html?h=3183'
})

//导航选项卡
$('.nav li').click(function () {
    $('.nav li').removeClass('active')
    $(this).addClass('active')
})

//返回顶部
window.onscroll = function () {
    if (document.documentElement.scrollTop > 300) {
        $('.Topping').css('display', 'block')
    } else {
        $('.Topping').css('display', 'none')
    }
}
$('.Topping').click(function () {
    console.log(1);
    let toping = setInterval(function () {
        document.documentElement.scrollTop -= 12
        if (document.documentElement.scrollTop <= 0) {
            clearInterval(toping);
        }
    }, 2)
})

// 生成列表   
let strArr = ``  //更多列表数据拼接
function list_more(itme) {
    let k = itme.length % 4
    let str2 = itme.map(function (is, index) {
        if (index < itme.length - k) {
            return `<div id='${is.id}'>
            <img src="${is.image}" alt="">
                <p>${is.title}</p>
                <p><span>淘宝</span><span>${is.isFreePostage ? '包邮' : '不包邮'}</span></p>
                <p>
                    <span>￥</span>
                    <span>${is.originPrice}</span>
                    <span>${is.saleNum}人已买</span>
                    <span>${is.couponValue}</span>
                </p>
        </div>`
        }
    })
    strArr += str2.join('')
    $('#morelist').html(strArr)
    details()
}

//商品列表
function list(itme) {
    let k = itme.length % 4
    let str = ``
    let str1 = itme.map(function (is, index) {
        if (index < itme.length - k) {
            return `<div id='${is.id}'>
            <img src="${is.image}" alt="">
                <p>${is.title}</p>
                <p><span>淘宝</span><span>${is.isFreePostage ? '包邮' : '不包邮'}</span></p>
                <p>
                    <span>￥</span>
                    <span>${is.originPrice}</span>
                    <span>${is.saleNum}人已买</span>
                    <span>${is.couponValue}</span>
                </p>
        </div>`
        }
    })
    str += str1.join('')
    $('#list').html(str)
    details()
}
//用户名
function logoin() {
    let username_x = localStorage.getItem('name_x')
    if (username_x == null) {
        return
    } else {
        $('.Sign').html(username_x)
    }
}
logoin()